//
//  MYGMeetScheduleTableViewCell.swift
//  MYDoctor
//
//  Created by Denny on 2024/5/28.
//

import UIKit

class MYGMeetScheduleTableViewCell: UITableViewCell {

    var models:[MYGScheduleCellModel]?{
        didSet {
            self.collectionView.reloadData()
        }
    }
    var meeting_id = ""
    @IBOutlet weak var collectionView: UICollectionView!
    override func awakeFromNib() {
        super.awakeFromNib()
        reloadCollectionViewLayout()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    func reloadCollectionViewLayout() {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        let leftMargin = 17.5
        layout.minimumLineSpacing = 15
        layout.minimumInteritemSpacing = 0
        layout.itemSize = CGSize(width: 145, height: 102)
        self.collectionView.register(nibWithCellClass: MYGMeetScheduleCollectionViewCell.self)
        self.collectionView.contentInset = UIEdgeInsets(top: 0, left: leftMargin, bottom: 0, right: leftMargin)
        
        self.collectionView.setCollectionViewLayout(layout, animated: false)
        self.collectionView.reloadData()
        self.collectionView.backgroundColor = .white
        self.collectionView.showsVerticalScrollIndicator = false
        self.collectionView.showsHorizontalScrollIndicator = false
        self.collectionView.delegate = self
        self.collectionView.dataSource = self
    }
    
}

extension MYGMeetScheduleTableViewCell:UICollectionViewDataSource,UICollectionViewDelegate {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.models!.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MYGMeetScheduleCollectionViewCell", for: indexPath) as! MYGMeetScheduleCollectionViewCell
        cell.model = self.models![indexPath.row]
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if indexPath.row == 0 {return}
        let vc = MYGAcademicSchuledDetailVC()
        let model =  self.models![indexPath.row]
        vc.id = "\(model.id)"
        UIViewController.currentViewController?.navigationController?.pushViewController(vc)
    }
    
}

